home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7863 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  42 lines

  1. Path: news.th-darmstadt.de!news
  2. From: enno@inferenzsysteme.informatik.th-darmstadt.de (Enno Sandner)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: new and delete with arrays
  5. Date: 17 Feb 1996 17:05:42 +0100
  6. Organization: Fachbereich Informatik, TH Darmstadt
  7. Sender: enno@kitz.inferenzsysteme.informatik.th-darmstadt.de
  8. Message-ID: <ltbumyey3t.fsf@kitz.inferenzsysteme.informatik.th-darmstadt.de>
  9. References: <4g4loa$i1l@mordred.gatech.edu>
  10. NNTP-Posting-Host: kitz.intellektik.informatik.th-darmstadt.de
  11. In-reply-to: Darin Heuermann's message of 17 Feb 1996 13:38:18 GMT
  12. X-Newsreader: Gnus v5.1
  13.  
  14. In article <4g4loa$i1l@mordred.gatech.edu> Darin Heuermann <gt1792a@prism.gatech.edu> writes:
  15.  
  16.    When I allocate an array of classes with delete, should delete call all of 
  17.    the instances' destructors?  Here is an example of what I mean.
  18.  
  19.    //**********************************************
  20.  
  21.    class MYCLASS {
  22.    public:
  23.       MYCLASS(void);
  24.       ~MYCLASS(void);
  25.    } // MYCLASS
  26.  
  27.    MYCLASS *myClass;
  28.  
  29.    myClass = new MYCLASS[10];
  30.    delete myClass;
  31.  
  32.    //**********************************************
  33.  
  34.    I would expect all 10 instances to call ~MYCLASS() when delete myClass is 
  35.    called, but only the first instance's destructor is being called.  Is the 
  36.    a bug in the compiler or is this how it's supposed to work?
  37.  
  38. The behavior of this code is undefined. You have to use 'delete[] myClass;'
  39. instead.
  40.  
  41.     Enno
  42.